const proc = require('child_process');
const fs = require('fs')
const path = require('path')
var childProcess = null;
start()

function start() {
  childProcess = proc.spawn('npx', ['electron', '.'], {
    // cwd: path.resolve(__dirname), // 找文件的目录是test目录下
    stdio: [0, 1, 2],
  });
}

function restart() {
  if (childProcess) {
    process.kill(childProcess.pid);
    childProcess = null;
    return;
  }
  childProcess = proc.spawn('npx', ['electron', '.'], {
    // cwd: path.resolve(__dirname), // 找文件的目录是test目录下
    stdio: [0, 1, 2],
  });
}
// console.log(childProcess.pid)
// process.kill(childProcess.pid);
fs.watch(path.resolve(__dirname, 'src'), {
  recursive: true
}, (eventType, filename) => {
  // console.log(eventType, filename)
  restart()
})